#pragma once

#include "Tetrisstd.h"

class CTexture
{
	public:
		IDirect3DTexture9 *texture;
		D3DXIMAGE_INFO info;

		CTexture();
		~CTexture();
		bool Create(int width,int height, IDirect3DDevice9* device);
		bool Load(std::string filename, IDirect3DDevice9* device, D3DCOLOR transcolor = 0xffff00ff);
		bool Save(std::string filename, _D3DXIMAGE_FILEFORMAT format = D3DXIFF_BMP);
		void Release();

		LPDIRECT3DTEXTURE9 getTexture() { return texture; }
		int getWidth();
		int getHeight();
		RECT getBounds();

	private:
		IDirect3DSurface9 *m_renderDepthStencilSurface;
		IDirect3DSurface9 *m_renderSurface;
};


class CSprite
{
public:
		CSprite();
		virtual ~CSprite() { }

		virtual void update(double deltaTime);
		virtual void draw(ID3DXSprite* spriteHandler);

		void setImage(std::shared_ptr<CTexture> image);
		void setWidth(int value) { m_width = value; }
		int getWidth() { return m_width; }
		void setHeight(int value) { m_height = value; }
		int getHeight() { return m_height; }
		void setRotation(double value) { m_rotation = value; }
		double getRotation() { return m_rotation; }
		void setColor(D3DXCOLOR value) { m_color = value; }
		D3DXCOLOR getColor() { return m_color; }
		void setPosition(D3DXVECTOR3 value) { m_position = value; }
		D3DXVECTOR3 getPosition() const { return m_position; }
		void setScale(D3DXVECTOR3 value) { m_scale = value; }
		D3DXVECTOR3 getSCale() const { return m_scale; }
		D3DXMATRIX getWorld() { return m_world; }

	protected:
		void transform();

		std::shared_ptr<CTexture> m_image;

	private:
		int m_width, m_height;
		double m_rotation;
		D3DXCOLOR m_color;

		D3DXVECTOR3 m_position;
		D3DXVECTOR3 m_scale;
		D3DXMATRIX m_world;
};